package com.tsj.spzx.user.controller;

import com.alipay.api.domain.RegionInfo;
import com.tsj.spzx.model.entity.user.UserAddress;
import com.tsj.spzx.model.vo.common.Result;
import com.tsj.spzx.model.vo.common.ResultCodeEnum;
import com.tsj.spzx.user.service.UserAddressService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user/userAddress")
@Tag(name="用户地址接口")
public class UserAddressController {

    @Autowired
    private UserAddressService userAddressService;

    /**
     * 查询用户的地址列表
     * @return
     */
    @GetMapping("/auth/findUserAddressList")
    public Result findUserAddressList() {
        List<UserAddress> userAddressList = userAddressService.findUserAddressList();
        return Result.build(userAddressList, ResultCodeEnum.SUCCESS);
    }

    /**
     * 新增用户地址
     */
    @PostMapping("/auth/save")
    public Result save(@RequestBody UserAddress userAddress) {
        userAddressService.save(userAddress);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改用户地址
     * @param userAddress
     * @return
     */
    @PutMapping("/auth/updateById")
    public Result updateById(@RequestBody UserAddress userAddress) {
        userAddressService.updateById(userAddress);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 删除用户地址
     * @param id
     * @return
     */
    @DeleteMapping("/auth/removeById/{id}")
    public Result removeById(@PathVariable("id") Long id) {
        userAddressService.removeById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 远程调用 根据id查询地址信息
     * @param id
     * @return
     */
    @GetMapping("/getAddressById/{id}")
    public UserAddress getAddressById(@PathVariable("id") Long id) {
        UserAddress userAddress = userAddressService.getAddressById(id);
        return userAddress;
    }
}
